package com.juli.v2xdemo.util;

import android.content.Context;
import android.util.Log;
import android.view.View;

import com.juli.v2xdemo.PlaneWar;
import com.juli.v2xdemo.entity.OtherCar;
import com.juli.v2xdemo.listener.AddCarListener;

/**
 * Created by juli on 2019/9/28.
 */

public class OtherCar_Utils {
    public   static   OtherCar mCar;
    //初始位置
    static   float road_basex =1330 ;
    static   float road_1_x =850 +50;
    static   float road_2_x =1100 +50 ;
    static   float road_3_x =1330 +50;
    static   float road_4_x =1580+50 ;
    static  float road_basey = 900;
    static  float road_y = 800;
    public  static  void add_othercar(PlaneWar planeWar, Context context) {

          mCar = new OtherCar(context);
        mCar.setX(road_basex);
        mCar.setY(road_basey);
        mCar.setVisibility(View.INVISIBLE);
        mCar.getViewTreeObserver().addOnGlobalLayoutListener(
                new AddCarListener(mCar));
        planeWar.setOtherCar(mCar);
        planeWar.addView(mCar);
//        planeWar.moveHeroToOther(road_basex, road_basey);//变道-偏移角度注释掉该行
    }
//    OtherCar mCar2 = new OtherCar(MainActivity.this);
//        mCar2.setX(downother_x);
//        mCar2.setSety(downother_y);
//        mCar2.setVisibility(View.INVISIBLE);
//        mCar2.getViewTreeObserver().addOnGlobalLayoutListener(
//                new AddCarListener(mCar2));
//        planeWar.setOtherCar(mCar2);
//        planeWar.addView(mCar2);
    /**
     * 移动车到某条道路
     * @param road
     */
    static float currx=road_1_x;
    static    float curry=road_y;
    public  static void moveothercar(int road,PlaneWar planeWar,float  	distance){
//        distance=distance+550;
        switch (road) {
            case 1:

                planeWar.moveHeroToOther(road_1_x, road_y+ 	distance);
                currx=road_1_x;
                curry=road_y+ 	distance;
                Log.e("test1", "curry"+curry);
                break;
            case 2:
                planeWar.moveHeroToOther(road_2_x, road_y+distance);
                currx=road_2_x;
                curry=road_y+ 	distance;
                Log.e("test2", "curry"+curry);
                break;
            case 3:
                planeWar.moveHeroToOther(road_3_x, road_y+distance);
                currx=road_3_x;
                curry=road_y+ 	distance;
                Log.e("test3", "curry"+curry);
                break;
            case 4:
                planeWar.moveHeroToOther(road_4_x, road_y+distance);
                currx=road_4_x;
                curry=road_y+ 	distance;
                Log.e("test4", "curry"+curry);
                break;
            case 5:

                 curry=curry-2;
                Log.e("test5", "curry"+curry);
                planeWar.moveHeroToOther(currx, curry);

                break;

            default:
                break;
        }

    }
    public  static     void    othercar_visi(int type){
            if (type==1) {
                mCar.setVisibility(View.INVISIBLE);
            } else {
                mCar.setVisibility(View.INVISIBLE);
            }

     }

    public  static void getcarposition(){
//        float x  ;
//        int[] location = new int[2];
//        mCarData.getLocationOnScreen(location);
//        x = location[0];
//        float y = location[1];
//        Log.d("test", "Screenx--->" + x + "  " + "Screeny--->" + y);
//        mCarData.getLocationInWindow(location);
//        x = location[0];
//        y = location[1];
//        Log.d("test", "Window--->" + x + "  " + "Window--->" + y);
//        Log.d("test", "left:" + mCarData.getLeft());
//        Log.d("test", "right:" + mCarData.getRight());
//        Log.d("test", "Top:" + mCarData.getTop());
//        Log.d("test", "Bottom:" + mCarData.getBottom());
//        Log.d("test", "Width:"+mCarData.getWidth());
//        Log.d("test", "Height:"+mCarData.getHeight());
//        Screenx--->1091.0  Screeny--->721.0
//        Window--->1091.0  Window--->721.0
//        left:0
//        right:118
//        Top:0
//        Bottom:258
//        Width:118
//        Height:258
        Log.d("test", "TranslationX:"+mCar.getTranslationX());
        Log.d("test", "TranslationY:"+mCar.getTranslationY());
        Log.d("test", "X:"+mCar.getX());
        Log.d("test", "Y:"+mCar.getY());
//          //1091.0
//          // 721.0
//         X:1330.0
//         Y:900.0
    }



}
